package com.shycloud.mido.organ.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shycloud.mido.member.api.entity.OrgStudentDetailed;
import com.shycloud.mido.member.api.entity.OrgTeacherDetailed;
import com.shycloud.mido.organ.api.dto.OrganizationDTO;
import com.shycloud.mido.organ.api.dto.SysUserDto;
import com.shycloud.mido.organ.api.entity.*;
import com.shycloud.mido.organ.api.vo.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * @author danZ
 * @date 2019/6/3
 */
public interface OrganizationMapper extends BaseMapper<Organization> {

	int insertOptOrg(@Param("optId") Integer optId, @Param("orgId") Integer orgId);

	String getOrgNum(@Param("optId") Integer optId, @Param("isStudio") String isStudio);

	String getStudioNum(@Param("optId") Integer optId);

	int createSysUser(@Param("user") SysUserDto user);

	int createSysUserRole(@Param("userId") String userId);

	int getStudentNum(@Param("orgId") Integer orgId);

	int getTeacherNum(@Param("orgId") Integer orgId);

	IPage<NewStudentVO> getStudentList(IPage<NewStudentVO> page, @Param("orgId") Integer orgId, @Param("name") String name,
			@Param("sex") String sex, @Param("age") String age);

	List<NewStudentDetailVO> searchStudent(@Param("orgId") Integer orgId, @Param("keyword") String keyword);

	NewStudentDetailVO getStudentDetail(@Param("studentId") String studentId);

	IPage<NewTeacherVO> getTeacherList(IPage<NewTeacherVO> page, @Param("orgId") Integer orgId, @Param("name") String name,
			@Param("phone") String phone);

	Integer getStudentNumByTeacherId(@Param("teacherId") String teacherId);

	List<NewStudentDetailVO> getTeacherStudentList(@Param("teacherId") String teacherId);

	/**
	 * <p>Title: getOrganizationPage</p>
	 * <p>Description: 获取机构列表</p>
	 *
	 * @param page
	 * @param org
	 * @return
	 */
	IPage<OrganizationDTO> getOrganizationPage(IPage<OrganizationDTO> page, @Param("query") OrganizationDTO org);

	//ADDED

	/**
	 * <p>Title: getOrganizationPage</p>
	 * <p>Description: 获取机构列表</p>
	 *
	 * @param page
	 * @param org
	 * @return
	 */
	IPage<OrganizationDTO>
	getOrgPage(IPage<OrganizationDTO> page, @Param("query") OrganizationDTO org);

	//ADDED

	/**
	 * <p>Title: getOrganizationPage</p>
	 * <p>Description: 获取机构列表</p>
	 *
	 * @param page
	 * @param org
	 * @return
	 */
	IPage<OrganizationDTO> getStudioPage(IPage<OrganizationDTO> page, @Param("query") OrganizationDTO org);

	/**
	 * 通过id查询机构详情
	 *
	 * @param searchMap 机构详情Map
	 * @return Map<String, Object>
	 */
	List<Map<String, Object>> getOrganizationById(Map<String, Object> searchMap);

	/**
	 * <p>Title: addOrganization</p>
	 * <p>Description: 新增机构表</p>
	 *
	 * @param org 机构DTO
	 */
	void addOrganization(OrganizationDTO org);

	/**
	 * <p>Title: addOrgScope</p>
	 * <p>Description: 新增机构</p>
	 *
	 * @param scope 机构经营范围实体
	 * @return int
	 */
	int addOrgScope(OrgScope scope);

	/**
	 * @param baseorg 基础设置实体
	 * @return int
	 */
	int addbaseScope(BaseSetting baseorg);

	/**
	 * @param enrollorg 招生设置实体
	 * @return int
	 */
	int addenrollScope(EnRollSettingEntity enrollorg);

	/**
	 * @param pushorg 推送设置实体
	 * @return int
	 */
	int addpushScope(PushStatusEntity pushorg);

	/**
	 * 课程类别实体
	 *
	 * @param value
	 * @return int
	 */
	int addDicValueOne(LessonTypeDicEntity value);

	/**
	 * 课程类别实体
	 *
	 * @param value
	 * @return
	 */
	int addDicValueTwo(LessonTypeDicEntity value);

	/**
	 * 课程类别实体
	 *
	 * @param value
	 * @return
	 */
	int addDicValueThere(LessonTypeDicEntity value);

	/**
	 * <p>Title: updateOrganization</p>
	 * <p>Description: 编辑机构表</p>
	 *
	 * @param organization 机构实体
	 * @return int
	 */
	int updateOrganization(Organization organization);


	/**
	 * 机构购买课时
	 *
	 * @param org
	 * @return
	 */
	int updatePractice(Organization org);

	/**
	 * 机构购买课时流水
	 *
	 * @param org
	 * @return
	 */
	int addPurchase(OrganizationDTO org);

	/**
	 * <p>Title: deleteOrgScope</p>
	 * <p>Description: 根据id删除机构经营范围表数据</p>
	 *
	 * @param org 机构DTO
	 * @return int
	 */
	int deleteOrgScope(OrganizationDTO org);

	/**
	 * 根据memberId和orgId获取staff_detailed表是否存在数据
	 *
	 * @param organization 详情表实体
	 * @return int
	 */
	int queryStaffDetailedCount(Organization organization);

	/**
	 * <p>Description: 获取所有开启陪练的机构</p>
	 *
	 * @return OrganizationDTO
	 */
	List<OrganizationDTO> getOrganizationAccompany();

	/**
	 * <p>Description: 判断新增机构编码时是否存在</p>
	 *
	 * @return OrganizationDTO
	 */
	List<OrganizationDTO> getCode();

	/**
	 * 新增sys_user_role
	 *
	 * @param sysUserRole sysUserRole
	 */
	void addUserRole(SysUserRole sysUserRole);

	/**
	 * 查询sys_user_role
	 *
	 * @param sysUserRole sysUserRole
	 */
	List<SysUserRole> selectUserRole(SysUserRole sysUserRole);

	/**
	 * 查询教师是否申请过工作室
	 *
	 * @param phone 电话
	 * @return
	 */
	OrganizationDTO selectOrgById(String phone);

	/**
	 * @author: Whfeng
	 * @Date: 2019-10-12 16:13
	 * @Description: 查询所有机构信息(不带分页)
	 */
	List<Organization> list(@Param("org") Organization organization);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/14 14:47
	 * @Description: 更新单屈总数
	 */
	boolean updateSubtract(@Param("org") OrganizationDTO organizationDTO);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/14 14:47
	 * @Description: 更新双屈总数
	 */
	boolean updateDouble(@Param("org") OrganizationDTO organizationDTO);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/14 14:47
	 * @Description: 更新双屈总数
	 */
	boolean updateSum(@Param("org") OrganizationDTO organizationDTO);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/14 14:47
	 * @Description: 更新双屈总数
	 */
	boolean updateSumTwo(@Param("org") OrganizationDTO organizationDTO);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/22 10:22
	 * @Description: 机构订单插入
	 */
	boolean updateByWay(Organization organization);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/23 14:38
	 * @Description: 查询机构信息
	 */
	Organization selectOrganization(Organization organization);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/24 18:19
	 * @Description: 更新机构表可拍数量单屈
	 */
	boolean updateOrganizationType(StudentRefundEntity studentRefundEntity);

	/**
	 * @author: Cxc
	 * @Date: 2019/10/24 18:19
	 * @Description: 更新机构表可拍数量单屈
	 */
	boolean updateOrganizationTypeD(StudentRefundEntity studentRefundEntity);

	/**
	 * 更新机构权限
	 *
	 * @param org
	 * @return
	 */
	boolean updateOrg(Organization org);

	/**
	 * 查询机构列表
	 */
	IPage<OrderService> selList(Page page, @Param("phone") String phone, @Param("name") String name, @Param("code") String code,
			@Param("optId") String optId);

	/**
	 * 查询运营商列表
	 */
	IPage<OrderService> selOptr(Page page, @Param("phone") String phone, @Param("name") String name, @Param("code") String code);

	/**
	 * 根据运营商查询主键
	 *
	 * @param id
	 * @return
	 */
	OptOperator selOptrByid(@Param("id") String id);

	/**
	 * 查询软件产品列表
	 *
	 * @param orgId 机构id
	 * @return List<OrgGoodsVO>
	 */
	List<OrgGoodsVO> getOnlineProducts(Integer orgId);

	/**
	 * 更新运营商单驱双驱课
	 *
	 * @param optOperator
	 */
	void updOptr(@Param("data") OptOperator optOperator);

	/**
	 * 查询机构所排课节数
	 *
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	List<OrgClassVo> getOrgClassCount(@Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 查询某段时间的注册机构数
	 *
	 * @param startTime
	 * @return
	 */
	List<OrgCountVo> getOrgCount(@Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 查询某段时间的注册工作室数
	 *
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	List<OrgLicenseCountVo> getOrgLicenseCount(@Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 查询某段时间的注册会员数
	 *
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	List<MemberCountVo> getOrgMemberCount(@Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 分页获取工作室信息
	 *
	 * @param page
	 * @param officeName
	 * @param teacherName
	 * @return java.util.List<com.shycloud.mido.organ.api.vo.OfficeVO>
	 * @author nianhua.jiang
	 * @date 2020/6/3 10:38
	 */
	IPage<OfficeVO> getOffice(@Param("page") Page page, @Param("officeName") String officeName,
			@Param("teacherName") String teacherName);

	/**
	 * 获取工作室学生数量
	 *
	 * @param
	 * @return int
	 * @author nianhua.jiang
	 * @date 2020/6/4 9:48
	 */
	int getOfficeStudentCount();

	/**
	 * 查询工作室下的学生信息
	 *
	 * @param page
	 * @param phone
	 * @param studentName
	 * @param officeId
	 * @return com.baomidou.mybatisplus.core.metadata.IPage<com.shycloud.mido.organ.api.vo.OfficeStudentDetailVO>
	 * @author nianhua.jiang
	 * @date 2020/6/4 13:33
	 */
	IPage<OfficeStudentDetailVO> getOfficeStudentDetail(@Param("page") Page page, @Param("phone") String phone,
			@Param("studentName") String studentName, @Param("officeId") String officeId);

	/**
	 * 批量移除工作室的学生
	 *
	 * @param officeId
	 * @param studentIdList
	 * @return java.lang.Boolean
	 * @author nianhua.jiang
	 * @date 2020/6/4 15:22
	 */
	Boolean removeofficeStudent(@Param("officeId") Integer officeId, @Param("studentIdList") List<String> studentIdList);

	/**
	 * 查询学生
	 *
	 * @param name
	 * @param phone
	 * @return com.shycloud.mido.organ.api.vo.OfficeStudentDetailVO
	 * @author nianhua.jiang
	 * @date 2020/6/4 16:47
	 */
	List<OfficeStudentDetailVO> getStudent(@Param("name") String name, @Param("phone") String phone);

	int removeTeacherGroup(@Param("studentIdList") List<String> studentIdList);

	List<OrganizationVO> getOrgList(@Param("organization") OrganizationVO organization);

	String getSysUserCount(@Param("username") String username);

	int checkIsOrgRole(@Param("userId") String userId);

}
